package com.fyb;

import com.sun.corba.se.impl.orbutil.ObjectUtility;
import com.sun.org.apache.xml.internal.security.utils.JavaUtils;
import org.omg.CORBA.ARG_OUT;

import javax.swing.plaf.FontUIResource;
import java.util.Arrays;

public class maopao {
    public static void main(String[] args) {
        int[] a = {1,5,22,10,55,20};
/*
        for (int i = 0; i<a.length-1;i++){

            if (a[i]>a[i+1] ){
                int b = a[i];
                a[i]=a[i+1];
                a[i+1]=b;
            }
            System.out.println(a[i]);
        }
*/
      /*  Arrays.sort(a);
        for (int i = 1; i<a.length;i++){
            System.out.println(a[i]);
        }*/

     /*   for (int i = 0; i < a.length; i++) {

             for(int j = i+1;j<a.length;j++) {
                 if(a[i]>a[j]) {
                     int temp = a[i];
                     a[i] = a[j];
                     a[j] = temp;
                 }
             }
        }
        for (int k = 0; k <a.length ; k++) {
            System.out.println(a[k]);
        }
        */

        int count = 0;
          //外层循环控制的是比较的轮数:元素的个数-1
          /*     for(int i = 0;i<a.length - 1;i++){
                       //内层控制的是两两比较的次数
                     for(int j = i + 1;j<a.length;j++){
                           if(a[i] > a[j]){
                                int tmp = a[i];
                                  a[i] = a[j];
                                    a[j] = tmp;
                                      count++;
                            }
                        }
              }*/

        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {

                //比较的索引是j和j+1
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
            }

        for (int k = 0; k <a.length ; k++) {
            System.out.println(a[k]);
        }
             System.out.println("普通的选择排序,交换的次数是: " + count);

    }

}
